#!/usr/pkg/bin/perl -w

use warnings;
use strict;

use DBI;

my $graphpath = "/home/laszlo/public_html";

my @leagueids = (
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"11",
"12",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"44",
"45",
"46",
"47",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
"60",
"61",
"62",
"63",
"64",
"66",
"67",
"68",
"69",
"70",
"71",
"72",
"73",
"74",
"75",
"76",
"77",
"79",
"80",
"81",
"83",
"84",
"85",
"88",
"89",
"91",
"93",
"94",
"95",
"96",
"97",
"98",
"99",
"100",
"101",
"102",
"103",
"104",
"105",
"106",
"107",
"110",
"111",
"112",
"113",
"117",
"118",
"119",
"120",
"121",
"122",
"123",
"124",
"125",
"126",
"127",
"128",
"129",
"130",
"131",
"132",
"133",
"134",
"135",
"136",
"137",
"138"
);

my @dates = (
	"2006-04-03",
	"2006-03-13",
	"2006-02-20",
	"2006-02-03",
	"2006-01-13",
	"2005-12-23",
	"2005-12-01",
	"2005-11-09",
	"2005-10-19",
	"2005-09-29",
	"2005-09-08",
	"2005-08-24",
	"2005-07-28",
	"2005-07-08",
	"2005-06-16",
	"2005-05-28",
	"2005-05-06",
	"2005-04-15",
	"2005-03-26",
	"2005-03-04"
);

my @dates_new = (
	"2007-09-05",
	"2007-08-06",
	"2007-07-17",
	"2007-06-25",
	"2007-06-04",
	"2007-05-09",
	"2007-04-17",
	"2007-03-29",
	"2007-03-08",
	"2007-02-12",
	"2007-01-22",
	"2007-01-05",
	"2006-12-12",
	"2006-11-21",
	"2006-10-31",
	"2006-10-12",
	"2006-09-18",
	"2006-08-30",
	"2006-08-08",
	"2006-06-05",
	"2006-05-16",
	"2006-04-26"
);

foreach my $date (@dates_new) {
	dodate($date, 1, 0, $graphpath);
	dodate($date, 1, 1, $graphpath);
}

foreach my $date (@dates) {
	dodate($date, 0, 0, $graphpath);
	dodate($date, 0, 1, $graphpath);
}

sub dodate {
	my ($date,$new,$sup,$graphpath) = @_;
	my @subdirs = ("wosnaps", "supsnaps");
	my $subdir = $subdirs[$sup];

	foreach my $id (@leagueids) {
		my $maxlevel = 12;
		LEVEL:	for (my $level = 1; $level <= $maxlevel; $level++) {
			my $bs = 8;
			if ($level < 6) {
				$bs = 2**(9-$level);
			} elsif ($level >= 10) {
				$bs = 8-($new*4);
			}
			my $filename = $id . "_" . $level . "_" . "$date.png";
			next LEVEL if (-e "$graphpath/$subdir/$filename" && -s "$graphpath/$subdir/$filename");
			my $output = `wget -nv -O $graphpath/$subdir/$filename "http://websec.science.uva.nl/~lhoek/image.php?c=$id&l=$level&b=$bs&sup=$sup&date=$date&n=$new&nolog=1"`;
		}
	}
}

